#pragma once
#include <stdint.h>
#include <string>
#include <unordered_map>
#include "base/core/os/mutex.h"
#include "base/core/singleton.h"

struct TrackData 
{
	uint32_t    line_no_;
	std::string file_name_;
	std::string func_name_;

	TrackData(uint32_t line_no,
			  const char* file_name,
			  const char* func_name);
};

class MemTracker : public AutoSingleton<MemTracker> 
{
	friend class AutoSingleton<MemTracker>;
public:
	void PrintMemLink(const char* output_filename = NULL);
	bool TrackMalloc(void* ptr, const char* file_path, const char* func_num, uint32_t line_no);
	void TrackFree(void* ptr);

protected:
	std::string GetFileNameFromPath(const char* file_path);

protected:
	typedef MutexLock TMutexLock;
	typedef std::unordered_map<void*, TrackData> PtrTrackMap;

	TMutexLock   mutex_lock_;
	PtrTrackMap  ptr_track_map_;

protected:
	MemTracker();
	virtual ~MemTracker();
};

#define  g_MemTracker() (MemTracker::Instance())
